﻿using MediatR;
using System.CJL.API.Application.Command.StorageCommand;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.StorageCommandHandler
{
    /// <summary>
    /// 批量删除
    /// </summary>
    public class StorageDeletePiCommandHandler : IRequestHandler<StorageDeletePiCommand,int>
    {
        IStorageRepository _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repository"></param>
        public StorageDeletePiCommandHandler(IStorageRepository repository)
        {
            _repository=repository;
        }

        public async Task<int> Handle(StorageDeletePiCommand request, CancellationToken cancellationToken)
        {
            var list = (await _repository.GetAll()).Where(x=>request.id.Contains(x.StorageId));
            foreach (var item in list)
            {
                item.IsDelete = true;
                item.DelectName = "张三";
                item.DelectTime = DateTime.Now.ToUniversalTime();
                await _repository.UpdateAsync(item);
            }
            return 1;
        }
    }
}
